/*
 * $Id$
 */
package org.crazydays.gameplan.widget;


import java.awt.image.BufferedImage;

/**
 * AbstractWidget
 */
public abstract class AbstractWidget
    implements IWidget, Comparable<IWidget>
{
    /** serial version uid */
    public final static long serialVersionUID = "$Id$".hashCode();

    /** description */
    protected String description;

    /** icon */
    protected BufferedImage icon;

    /** buffered image */
    protected BufferedImage image;

    /**
     * Set description.
     * 
     * @param description Description
     */
    public void setDescription(String description)
    {
        this.description = description;
    }

    /**
     * Get description.
     * 
     * @return Description
     */
    public String getDescription()
    {
        return description;
    }

    /**
     * Set icon.
     * 
     * @param icon Icon
     */
    public void setIcon(BufferedImage icon)
    {
        this.icon = icon;
    }

    /**
     * Get icon.
     * 
     * @return Icon
     */
    public BufferedImage getIcon()
    {
        if (icon == null) {
            generateIcon();
        }

        return icon;
    }

    /**
     * Generate icon from image.
     */
    protected void generateIcon()
    {
        if (image == null) {
            return;
        }

        // TODO:
    }

    /**
     * Set image.
     * 
     * @param image Image
     */
    public void setImage(BufferedImage image)
    {
        this.image = image;
    }

    /**
     * Get image.
     * 
     * @return Image
     */
    public BufferedImage getImage()
    {
        return image;
    }

    /**
     * Get image.
     * 
     * @return HashCode
     * @see java.lang.Object#hashCode()
     */
    public int hashCode()
    {
        return getDescription().hashCode();
    }

    /**
     * Equals.
     * 
     * @param object Object
     * @return Equals
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object object)
    {
        if (object == null) {
            return false;
        }

        if (!(object instanceof IWidget)) {
            return false;
        }

        IWidget widget = (IWidget) object;
        if (!getDescription().equals(widget.getDescription())) {
            return false;
        }

        if (!getIcon().equals(widget.getIcon())) {
            return false;
        }

        if (!getImage().equals(widget.getImage())) {
            return false;
        }

        return true;
    }

    /**
     * Compate to widget.
     * 
     * @param widget Widget
     * @return Widget
     * @see Comparable#compareTo(Object)
     */
    public int compareTo(IWidget widget)
    {
        return getDescription().compareTo(widget.getDescription());
    }
}
